package cdc.retrofit.official.jsonandxmlconverters;
import java.io.IOException;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
@SuppressWarnings("deprecation")
public class JsonAndXmlConverters {
	  public static void main(String... args) throws IOException {
		    MockWebServer server = new MockWebServer();
		    server.start();
		    server.enqueue(new MockResponse().setBody("{\"name\": \"Jason\"}"));
		    server.enqueue(new MockResponse().setBody("<user name=\"Eximel\"/>"));

		    Retrofit retrofit = new Retrofit.Builder()
		        .baseUrl(server.url("/"))
		        .addConverterFactory(new QualifiedTypeConverterFactory(
		            GsonConverterFactory.create(),
		            SimpleXmlConverterFactory.create()))
		        .build();
		    Service service = retrofit.create(Service.class);

		    User user1 = service.exampleJson().execute().body();
		    System.out.println("User 1: " + user1.name);

		    User user2 = service.exampleXml().execute().body();
		    System.out.println("User 2: " + user2.name);

		    server.shutdown();
		  }

}
